<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <title>用户登陆</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/bootstrap-theme.min.css" rel="stylesheet">
</head>

<body>
<div class="container-fluid">
    <form class="form-horizontal" action="/user/login" method="post" id="login">
        <div class="form-group">
            <label class="col-sm-2 control-label">用户名</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="username" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">密码</label>
            <div class="col-sm-10">
                <input type="password" class="form-control" name="password" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">验证码</label>
            <div class="col-sm-1">
                <input type="text" class="form-control" name="captcha" required>
                <img width="83" height="30" title="获得验证码" id="captcha" src="">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"> 记住我
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="btn btn-default" id="login-btn">登陆</button>
            </div>
        </div>
    </form>
</div>
<script src="/js/jquery.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script>
    document.getElementById("captcha").onclick = function () {
        this.src = "/user/captcha?rnd=" + Math.random();
    };
    $("#login-btn").on("click", function () {
        var form = $("#login");

        $.ajax({
            url: $(form).attr('action'), type: 'post',
            data: $(form).serialize(),
            success: function (result) {
                if (result.code == 0) {
                    window.location.href = result.data;
                } else {
                    alert(result.message);
                }
            }
        });
    });
</script>
</body>
</html>